package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Date;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.entity.FyClassTableEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.FyPhotoEntity;
import io.renren.modules.sys.service.FyPhotoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-03-04 11:18:52
 */
@RestController
@RequestMapping("sys/fyphoto")
public class FyPhotoController {
    @Autowired
    private FyPhotoService fyPhotoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:fyphoto:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = fyPhotoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{photoId}")
    @RequiresPermissions("sys:fyphoto:info")
    public R info(@PathVariable("photoId") Integer photoId){
        FyPhotoEntity fyPhoto = fyPhotoService.getById(photoId);

        return R.ok().put("fyPhoto", fyPhoto);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:fyphoto:save")
    public R save(@RequestBody FyPhotoEntity fyPhoto){
        long time = new Date().getTime()/1000;
        fyPhoto.setCreattime(Integer.parseInt(String.valueOf(time)));
        fyPhotoService.save(fyPhoto);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:fyphoto:update")
    public R update(@RequestBody FyPhotoEntity fyPhoto){
        ValidatorUtils.validateEntity(fyPhoto);
        fyPhotoService.updateById(fyPhoto);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:fyphoto:delete")
    public R delete(@RequestBody Integer[] photoIds){
        fyPhotoService.removeByIds(Arrays.asList(photoIds));

        return R.ok();
    }

    /**
     * 查询所有相册信息
     */
    @RequestMapping("/alllist")
    @RequiresPermissions("sys:fyphoto:alllist")
    public R alllist(){
        List<FyPhotoEntity> alllist = fyPhotoService.list(new QueryWrapper<FyPhotoEntity>());
        return R.ok().put("alllist", alllist);
    }

}
